<?php
	defined('IN_WEB') or die('Include Error!');
	error_reporting( 0);	
	set_time_limit( 10);   //设置脚本执行时间
	mb_internal_encoding("UTF-8");  //设置编码
	date_default_timezone_set('Asia/Shanghai');//设置时区
		
	define('WWWROOT',  dirname(__FILE__) . '/');
	define('PATH_CONFIG', WWWROOT . 'config/');
	define('PATH_LIB', WWWROOT . 'lib/');
	define('PATH_DATA', WWWROOT . 'data/');
	define('PATH_MODEL', WWWROOT . 'model/');
	define('PATH_LANG', WWWROOT . 'lang/');
	define('API_PATH', WWWROOT . 'api/');
	define('INC_PATH_', WWWROOT . 'includes/');
	
	include(WWWROOT . 'config/config.inc.php');
	
	//只有在非产品非命令行(防止僵尸进程)才打开错误
	PRODUCTION_SERVER or (PHP_SAPI == 'cli') or error_reporting(E_ALL ^ E_NOTICE); 
	
	include PATH_CONFIG . 'config.common.php';
	include PATH_CONFIG . 'config.system.php';
	include PATH_CONFIG . 'config.explevels.php';
	include PATH_CONFIG . 'config.property.php';
	include PATH_CONFIG . 'config.sngall.php';
	include PATH_CONFIG . 'config.faces.php';
	include PATH_CONFIG . 'config.newexp.php';
	
	include(PATH_MODEL . 'go.php');
	include(PATH_MODEL . 'odb.php'); //实现根据业务分db
    include(PATH_MODEL . 'okey.php');  //分配cachekey
    include(PATH_MODEL . 'ovalue.php'); //序列反序列cache数组
    include(PATH_MODEL . 'ocache.php'); //实现根据业务分cache
	include(PATH_MODEL . 'otable.php'); //实现根据业务分table
	include(PATH_MODEL . 'of.php'); //项目相关的静态方法
	
	include(PATH_LIB . 'functions.oo.php');
	include(PATH_LIB . 'functions.php');
	
	go::setConfig( $config);

	if ( PRODUCTION_SERVER && ($config['pagestatrand'] > 1) && (rand(1, $config['pagestatrand']) == 1)) {  //正式环境并且概率配置大于1（config.system.php）
		set_error_handler(array('functions','errorlog'), E_ALL ^ E_NOTICE); //语法错误日志
		function check_shutdown( $stime){
			function_exists('fastcgi_finish_request') && fastcgi_finish_request(); //快速返回浏览器
			$file = $_SERVER['PHP_SELF'].(isset($GLOBALS['amfphp']['targetURI']) ? '-'.$GLOBALS['amfphp']['targetURI'] : ''); //取当前执行文件名
			oo::udp()->send(5002, $file, microtime( true)-$stime, odb::count(), ocache::count());
		}
		register_shutdown_function('check_shutdown', microtime( true));
	}

    if( ( PHP_SAPI != 'cli' ) && ( !defined('PRODUCTION_SERVER') || !PRODUCTION_SERVER ) ){//对非正式环境进行IP检查
		$ip = functions::getip();
		$aAllowedIp= array('183.62.196.10','183.62.196.12','219.84.165.161','222.126.155.228','219.84.165.163','219.84.165.162','210.22.15.226','65.49.68.152','175.45.32.166','218.213.86.10','222.126.155.230');
		$aIpv4 = explode('.',$ip);
		if( (!in_array( $ip, $aAllowedIp ) ) && (( !in_array( $aIpv4[0], array('127','192','172','10') ) ) || ( $aIpv4[0] == '192' && $aIpv4[1] != '168' ) || ( $aIpv4[0] == '172' && ( $aIpv4[1] < 16 || $aIpv4[1] > 31 ) ) ) ){
			echo '<!--',$ip,'-->';
			die('operation is not found.');
		}
		unset($ip,$aAllowedIp,$aIpv4);
	}
	functions::header();

	if(! in_array(oo::$config['sid'], array(13,101))){
		oo::black()->check(); //检查IP是否被封
	}
	
	if(oo::$config['bc'] || ( oo::$config['use_kvstorage'] > 0 ) ) {
		include_once(PATH_LIB .'class.bc.php');
		BCache::$requirePrefix = PATH_MODEL .'bc/';
		BCache::loadConfig(PATH_CONFIG .'config.bc.php');
	}